<template>
  <!-- <a-modal v-model="visible" centered :footer="null"  :closable="false"> -->
    <!-- <div class="n-dialog-mask" @click="handleClose"></div> -->
    <div class="n-dialog-container notice-modal">
      <div class="notice-header">
        <div class="notice-tab">
          <a :class="{'active':params.type==''}" @click="chooseTab('')">全部通知</a>
          <a :class="{'active':params.type==6}" @click="chooseTab(6)">评论</a>
          <!-- <a :class="{'active':tab==2}" @click="chooseTab(2)">@我</a> -->
          <a :class="{'active':params.type==25}" @click="chooseTab(25)">喜欢</a>
        </div>
        <a class="close-dialog-btn"  @click="$emit('close')"></a>
      </div>
      <div class="notice-data-wrap">
        <ul class="notice-datas" @scroll="onScroll">
            <li v-for="(item,idx) in list" :key="idx">
            <!-- 评论了xx 作品 -->
            <template  v-if="item.type==6||item.type==3">
                <div class="lt">
                  <a class="basic" :href="'/user/'+item.sendMember.id" target="_blank">
                    <img loading="lazy" class="avatar" v-aimgd="{avatar:item.sendMember.avatar,id:item.sendMember.id,w:50,name:item.sendName}"/>
                  </a>
                  <div class="word-basic">
                    <a class="name"  :href="'/user/'+item.sendMember.id" target="_blank">{{item.sendName}}</a>
                    <div class="desc" v-if="item.comment" v-html="'发表了评论: '+item.comment.content">
                    </div>
                    <div class="desc" v-else v-html="'发表了评论: '+item.content">
                    </div>
                    <div class="action">{{item.intervalTimeStr}}</div>
                    </div>
                </div>
                <a class="cover" v-if="item.article" :href="infoUrlEnum[item.article.topCategory.id].url+item.article.id" target="_blank">
                    <img loading="lazy" v-imgd="{ id: item.article.id, w: 312, uptime: item.updateTime }" />
                </a>
                <!-- <a class="n-attention" v-else>回关</a> -->
            </template>
            <!-- 赞了xx -->
            <template  v-else-if="item.type==25||item.type==2||item.type==5">
                <div class="lt">
                    <a class="basic" :href="'/user/'+item.sendMember.id" target="_blank">
                      <img loading="lazy" class="avatar" v-aimgd="{avatar:item.sendMember.avatar,id:item.sendMember.id,w:50,name:item.sendName}"/>
                    </a>
                    <div class="word-basic">
                      <a class="name"  :href="'/user/'+item.sendMember.id" target="_blank">{{item.sendName}}</a>
                    <div class="desc" v-html="item.content">
                    </div>
                    <div class="action">{{item.intervalTimeStr}}</div>
                    </div>
                </div>
                <a class="cover" v-if="item.article" :href="infoUrlEnum[item.article.topCategory.id].url+item.article.id" target="_blank">
                    <img loading="lazy" v-imgd="{ id: item.article.id, w: 312, uptime: item.updateTime }" />
                </a>
                <!-- <a class="n-attention" v-else>回关</a> -->
            </template>
            <template  v-else-if="item.type==4">
                <div class="lt">
                    <a class="basic" :href="'/user/'+item.sendMember.id" target="_blank">
                      <img loading="lazy" class="avatar" v-aimgd="{avatar:item.sendMember.avatar,id:item.sendMember.id,w:50,name:item.sendName}"/>
                    </a>
                    <div class="word-basic">
                      <a class="name"  :href="'/user/'+item.sendMember.id" target="_blank">{{item.sendName}}</a>
                    <div class="desc">
                        关注了你
                    </div>
                    <div class="action">{{item.intervalTimeStr}}</div>
                    </div>
                </div>
                <span class="cover" v-if="item.type=='5'&&item.article">
                    <img loading="lazy" v-imgd="{ id: item.article.id, w: 312, uptime: item.updateTime }" />
                </span>
                <!-- <a class="n-attention" v-else>回关</a> -->
            </template>
            <template  v-else-if="item.type==0">
                <div class="lt">
                    <div class="basic">
                      <img loading="lazy" class="avatar" :src="sysAvatar" @error="onImgError"/>
                    </div>
                    <div class="word-basic">
                    <div class="name">系统通知</div>
                    <div class="desc" v-html="item.content">
                    </div>
                    <div class="action">{{item.intervalTimeStr}}</div>
                    </div>
                </div>
                <a class="cover" v-if="item.article" :href="infoUrlEnum[item.article.topCategory.id].url+item.article.id" target="_blank">
                    <img loading="lazy" v-imgd="{ id: item.article.id, w: 312, uptime: item.updateTime }" />
                </a>
            </template>
            </li>
        </ul>
      </div>
    </div>
  <!-- </a-modal> -->
</template>

<script>
import SparkMD5 from 'spark-md5'
import api from '@/api/api'
export default {
    data(){
        return{
          scrolllLoaded:false,
            infoUrlEnum: {
                22: { url: '/game/', name: '游戏' },
                1: { url: '/work/', name: '作品' },
                50: { url: '/video/', name: '短视频' },
                9: { url: '/article/', name: '文章' }
            },
          visible:false,
			      sysAvatar:require('../assets/sys_avatar.png'),
            tab:0,
            list:[],
            totalPage:0,
            params:{
                pageNum:1,
                pageSize:10,
                type:''
            }
        }
    },
    destroyed(){
        // document.body.style.overflow='inherit'
    },
    methods:{
        onScroll(e) {
            if(this.scrolllLoaded==false)return;
            let spacNum = e.target.scrollHeight - ($(e.target).scrollTop() + $(e.target).height());
            if (spacNum < 1 && this.totalPage != this.params.pageNum) {
                this.scrolllLoaded=false;
                this.params.pageNum++
                this.queryList()
            }
        },
        version(time) {
            let date = new Date(time)
            return date.getTime()
        },
        onImgError(e){
            e.target.src=require('../assets/pro/default_uimg.svg');
        },
         get_avatar_url(member = { id: '', avatar: '' }, n = 1, w = 30) {
            if (!member.id || !member.avatar) return this.defaultAvatar
            let hash = SparkMD5.hash(member.avatar).slice(0, 6)
            return `https://img.gameui.net/avatar-${member.id}-${hash}@${n}x${w}.webp`
        },
        get_avatar_urls(member = { id: '', avatar: '' }, w = 30) {
            return `${this.get_avatar_url(member, 1, w)} 1x, ${this.get_avatar_url(member, 2, w)} 2x, ${this.get_avatar_url(member, 3, w)} 3x`
        },
        handleClose(){
            this.$emit('close')
        },
        chooseTab(_tab){
            this.params.type=_tab;
            this.list=[];
            this.scrolllLoaded=false;
            this.params.pageNum=1;
            this.queryList()
        },
        async queryList(){
            let params=Object.assign({},this.params);
            if(!params.type){
              delete params.type;
            }
            let res=await api.noticesList(params);
            let that=this;
            res.data.map(r=>{
              if(r.type!=0)
              {
                r.content=that.$bhelper.replace_em(r.content);
                if(r.comment){
                  r.comment.content=that.$bhelper.replace_em(r.comment.content);
                }
              }
            })
            this.list=[...this.list,...res.data];

            let rsnum = res.total % params.pageSize
            this.totalPage= rsnum == 0 ? res.total / params.pageSize : parseInt(res.total / params.pageSize + 1);

            setTimeout(()=>{
              that.scrolllLoaded=true;
            },1000)
        }
    },
    mounted(){
        // document.body.style.overflow='hidden'
        this.queryList();
    }
}
</script>

<style scoped lang="less">
.notice-modal {
  width: 860px;
  left: calc((100% - 860px) / 2);
  border-radius: 30px;
  box-shadow: 0px 0px 12px 3px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  .notice-header {
    height: 80px;
    line-height: 80px;
    padding-left: 30px;
    padding-right: 30px;
    background: #23232a;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .notice-tab {
      font-size: 18px;
      color: #969696;
      > a {
        margin-right: 30px;
      }
      .active {
        font-weight: 500;
        color: #fff;
        position: relative;
        &:after {
          content: '';
          position: absolute;
          bottom: -5px;
          width: 24px;
          height: 2px;
          background: #11CCB1;
          border-radius: 2px;
          left: calc((100% - 24px) / 2);
        }
      }
    }
    .close-dialog-btn {
      width: 18px;
      height: 18px;
      background: url('../assets/pro/close-win.svg') no-repeat;
      background-size: cover;
      transition:.1s all linear;
      &:hover{
        transform: rotate(180deg);
      }
    }
  }
}
.notice-data-wrap{
  padding:20px 10px 30px 30px;
  background: #2e2d31;
}
.notice-datas {
//   padding: 20px 0px 30px 30px;
    min-height:545px;
    max-height:545px;
    padding-right:10px;
    overflow-y:auto;
    /*滚动条整体部分,必须要设置*/
    &::-webkit-scrollbar{
        width: 3px;
        height: 8px;
        background-color: transparent;
    }
    /*滚动条的轨道*/
    &::-webkit-scrollbar-track{
        background-color: transparent;
    }
    /*滚动条的滑块按钮*/
    &::-webkit-scrollbar-thumb{
        border-radius: 3px;
        background-color: #626262;
    }
    /*滚动条的上下两端的按钮*/
    &::-webkit-scrollbar-button{
        height: 0;
    }
    
    /* 两个滚动条的交汇处 */
    &::-webkit-scrollbar-corner{
        background-color: transparent;
    }
  li {
    color: #fff;
    display: flex;
    align-items:flex-start;
    width: 100%;
    justify-content: space-between;
    margin-bottom: 35px;
    .lt {
      display: flex;
      // align-items: center;
        align-items: flex-start;
      
      max-width:calc(100% - 167px);
      .basic {
        margin-right: 15px;
        
        width: 60px;
        min-width:60px;
        height: 60px;
        border-radius: 60px;
        overflow: hidden;
        &:hover{
          img{
            transform: scale(1.08);
          }
        }
        .avatar {
          object-fit: cover;
          width:100%;
          height:100%;
        }
      }
      .word-basic {
        .name {
          font-size: 16px;
          font-weight: 500;
          line-height: 22px;
          &:hover{
            color:#11CCB1;
            text-decoration: underline;
          }
        }
        .desc {
          font-size: 14px;
          line-height: 20px;
          margin: 2px 0px;
          width:100%;
          width:100%;
          ::v-deep img{
            width:20px;
            margin:0px 3px;
          }
          ::v-deep *{
            color:#fff !important;
            background:#2e2d31 !important;
            
          }
          ::v-deep .hight-str{
                color:#11CCB1 !important;
            }
        }
        .action {
          color: #969696;
          font-size: 14px;
          line-height: 20px;
        }
      }
    }
    .n-attention {
      width: 90px;
      min-width:90px;
      text-align: center;
      border-radius: 10px;
      line-height: 40px;
      background: #11CCB1;
      font-size: 16px;
      font-weight: 500;
      margin-left:100px;
    }
    .n-xh-attention {
      width: 90px;
      text-align: center;
      border-radius: 10px;
      line-height: 40px;
      background: #34323a;
      font-size: 16px;
      font-weight: 500;
    }
    .cover {
      width: 67px;
      height: 67px;
      min-width:67px;
      margin-left:100px;
      border-radius: 8px;
      overflow: hidden;
      &:hover{
        img{
          transform: scale(1.08)
        }
      }
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
  }
}























































































</style>